package br.com.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value="validaCpf")
public class ValidaCPF implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String cpf = String.valueOf(value);
        if (!validaCPF(cpf)) {
            FacesMessage msg = new FacesMessage();
            msg.setSummary("CPF Inválido");
            throw new ValidatorException(msg);
        }
    }

    public static boolean validaCPF(String cpf) {
        if (cpf.equals("11111111111")) {
            return false;
        }
        return true;
    }
}
